﻿using System;

namespace Task4_interface_
{
    //define Interface of Shape
    public interface IShape
    {
        double Area();
        bool IsValid();
    }
    
    public class Rectangle : IShape
    {
        private double width;
        private double height;

        public Rectangle(double width, double height)
        {
            this.width = width;
            this.height = height;
        }
        
        public double Width
        {
            get { return width; }
            set { width = value; }
        }

        public double Height
        {
            get { return height; }
            set { height = value; }
        }
        
        public double Area()
        {
            return width * height;
        }
        
        public bool IsValid()
        {
            return width > 0 && height > 0;
        }
    }
    
    public class Square : IShape
    {
        private double sideLength;

        public Square(double side)
        {
            this.sideLength = side;
        }
        
        public double Side
        {
            get { return sideLength; }
            set { sideLength = value; }
        }
        
        public double Area()
        {
            return sideLength * sideLength;
        }
        
        public bool IsValid()
        {
            return sideLength > 0;
        }
    }
    
    public class Triangle : IShape
    {
        private double side1;
        private double side2;
        private double side3;

        public Triangle(double side1, double side2, double side3)
        {
            this.side1 = side1;
            this.side2 = side2;
            this.side3 = side3;
        }
        
        public double Side1
        {
            get { return side1; }
            set { side1 = value; }
        }

        public double Side2
        {
            get { return side2; }
            set { side2 = value; }
        }

        public double Side3
        {
            get { return side3; }
            set { side3 = value; }
        }
        
        public double Area()
        {
            double s = (side1 + side2 + side3) / 2;
            return Math.Sqrt(s * (s - side1) * (s - side2) * (s - side3));
        }
        
        public bool IsValid()
        {
            return side1 + side2 > side3 && side1 + side3 > side2 && side2 + side3 > side1 && side1 > 0 && side2 > 0 && side3 > 0;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Rectangle rectangle = new Rectangle(6, 9);
            Console.WriteLine($"Area of the Reactangle：{rectangle.Area()}");
            
            Square square = new Square(5);
            Console.WriteLine($"Area of the Square：{square.Area()}");

            Triangle triangle = new Triangle(3, 4, 5);
            Console.WriteLine($"Area of the Triangle：{triangle.Area()}");
            
            rectangle.Width = 4;
            rectangle.Height = 5;
            Console.WriteLine($"Area of the modified Reactangle：{rectangle.Area()}");
            
            square.Side = 5;
            Console.WriteLine($"Area of the modified Square：{square.Area()}");
            
            triangle.Side1 = 5;
            triangle.Side2 = 12;
            triangle.Side3 = 13;
            Console.WriteLine($"Area of the modified Triangle：{triangle.Area()}");
            
        }
    }
}
